package com.ruoyi.be.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.be.domain.MedicalCpoeBed;
import com.ruoyi.be.service.IMedicalCpoeBedService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 床位记录Controller
 * 
 * @author ruoyi
 * @date 2022-01-05
 */
@RestController
@RequestMapping("/be/bed")
public class MedicalCpoeBedController extends BaseController
{
    @Autowired
    private IMedicalCpoeBedService medicalCpoeBedService;

    /**
     * 查询床位记录列表
     */
    @PreAuthorize("@ss.hasPermi('be:bed:list')")
    @GetMapping("/list")
    public TableDataInfo list(MedicalCpoeBed medicalCpoeBed)
    {
        startPage();
        List<MedicalCpoeBed> list = medicalCpoeBedService.selectMedicalCpoeBedVo();
        return getDataTable(list);
    }

    /**
     * 查询床位记录列表
     */
    @PreAuthorize("@ss.hasPermi('be:bed:query')")
    @GetMapping("/query")
    public TableDataInfo query(String sickroomname)
    {
        startPage();
        List<MedicalCpoeBed> list = medicalCpoeBedService.selectMedicalCpoeBedListName(sickroomname);
        return getDataTable(list);
    }

    /**
     * 导出床位记录列表
     */
    @PreAuthorize("@ss.hasPermi('be:bed:export')")
    @Log(title = "床位记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MedicalCpoeBed medicalCpoeBed)
    {
        List<MedicalCpoeBed> list = medicalCpoeBedService.selectMedicalCpoeBedList(medicalCpoeBed);
        ExcelUtil<MedicalCpoeBed> util = new ExcelUtil<MedicalCpoeBed>(MedicalCpoeBed.class);
        util.exportExcel(response, list, "床位记录数据");
    }
    /**
     * 获取病房记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('be:bed:query')")
    @GetMapping(value = "/{sickroomname}")
    public AjaxResult getcw(@PathVariable("sickroomname") String sickroomname)
    {
        return AjaxResult.success(medicalCpoeBedService.selectMedicalCpoeBedbysickroomname(sickroomname));
    }


    /**
     * 获取床位记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('be:bed:query')")
    @GetMapping(value = "/bed/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(medicalCpoeBedService.selectMedicalCpoeBedById(id));
    }

    /**
     * 新增床位记录
     */
    @PreAuthorize("@ss.hasPermi('be:bed:add')")
    @Log(title = "床位记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MedicalCpoeBed medicalCpoeBed)
    {
        medicalCpoeBed.setId(SecurityUtils.getUsername()+new Date().getTime());
        return toAjax(medicalCpoeBedService.insertMedicalCpoeBed(medicalCpoeBed));
    }

    /**
     * 修改床位记录
     */
    @PreAuthorize("@ss.hasPermi('be:bed:edit')")
    @Log(title = "床位记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MedicalCpoeBed medicalCpoeBed)
    {
        return toAjax(medicalCpoeBedService.updateMedicalCpoeBed(medicalCpoeBed));
    }

    /**
     * 删除床位记录
     */
    @PreAuthorize("@ss.hasPermi('be:bed:remove')")
    @Log(title = "床位记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(medicalCpoeBedService.deleteMedicalCpoeBedByIds(ids));
    }
}
